package io.renren.modules.pms.controller;

import java.util.Arrays;
import java.util.Map;

import io.renren.common.validator.ValidatorUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.renren.modules.pms.entity.OrderItemEntity;
import io.renren.modules.pms.service.OrderItemService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;



/**
 * 订单明细表
 *
 * @author Mark
 * @email sunlightcs@gmail.com
 * @date 2024-08-14 21:14:04
 */
@RestController
@RequestMapping("pms/orderitem")
public class OrderItemController {
    @Autowired
    private OrderItemService orderItemService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("pms:orderitem:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = orderItemService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{itemId}")
    @RequiresPermissions("pms:orderitem:info")
    public R info(@PathVariable("itemId") Long itemId){
        OrderItemEntity orderItem = orderItemService.getById(itemId);

        return R.ok().put("orderItem", orderItem);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("pms:orderitem:save")
    public R save(@RequestBody OrderItemEntity orderItem){
        orderItemService.save(orderItem);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("pms:orderitem:update")
    public R update(@RequestBody OrderItemEntity orderItem){
        ValidatorUtils.validateEntity(orderItem);
        orderItemService.updateById(orderItem);
        
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("pms:orderitem:delete")
    public R delete(@RequestBody Long[] itemIds){
        orderItemService.removeByIds(Arrays.asList(itemIds));

        return R.ok();
    }

}
